﻿using System.Linq;
using Dolany.UtilityTool;
using JetBrains.Annotations;
using Missbot.AIModule.Base;
using Missbot.AIModule.Schedulers.DailyVtuber;
using Missbot.Core.Base;

namespace Missbot.AIModule.Modules.Vtuber
{
    [UsedImplicitly]
    public class VtuberMod : IAIModule
    {
        public override string Name => "Vtuber";
        public override string ParentTag => "嘟嘟互动";

        public VtuberPicSvc VtuberPicSvc { get; set; }

        protected override bool OnInboxImpl(InboxSession session)
        {
            if (base.OnInboxImpl(session))
            {
                return true;
            }

            if (!(session.User is { IsAdmin: true }) || session.Channel.BindingType != ChannelType.Note)
            {
                return false;
            }

            if (session.Tags.IsNullOrEmpty() || !session.Tags.Contains("vtuber") || session.Tags.Length <= 1)
            {
                return false;
            }

            if (session.Files.IsNullOrEmpty())
            {
                return false;
            }

            var tags = session.Tags.Except(new[] { "vtuber" });
            var count = tags.Sum(tag => session.Files.Count(file => VtuberPicSvc.PicUpload(tag, file.Url, file.IsSensitive)));

            session.SendBack($"上传成功！成功数量：{count}");
            return true;
        }
    }
}